package cq.zhcqk.activity;

import android.graphics.Bitmap;
import android.os.Build;
import android.view.View;
import android.webkit.WebSettings;
import android.widget.ImageView;
import android.widget.TextView;

import com.dou361.dialogui.DialogUIUtils;
import com.tencent.smtt.export.external.interfaces.SslError;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import cq.zhcqk.R;
import cq.zhcqk.base.BaseActivity;
import cq.zhcqk.util.WebViewHeader;
import cq.zhcqk.util.x5.X5WebView;

/**
 * Created by zhangle on 2018/3/4.
 */
public class WJDCDetailActivity extends BaseActivity implements View.OnClickListener{
    private String pageUrl;
    private X5WebView tc_webview;
    @Override
    protected void initView() {
        setContentView(R.layout.activity_start_page);
        pageUrl = getIntent().getStringExtra("openUrl");
//        pageUrl = "https://www.wenjuan.in/s/UnyEZfW/";
        tc_webview = (X5WebView) findViewById(R.id.tc_webview);
        com.tencent.smtt.sdk.WebSettings webSettings = tc_webview.getSettings();
        webSettings.setDomStorageEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
    }

    @Override
    protected void initData() {
        initBack();
        WebViewHeader.setHeaderAndLoadX5(tc_webview, pageUrl);
        show();
    }

    private void initBack(){
        ImageView back = (ImageView) findViewById(R.id.header_back);
        TextView title = (TextView) findViewById(R.id.header_text);
        title.setText("和美磁器口");
        back.setOnClickListener(this);
    }

    public void show(){
        if(tc_webview != null)
        {
            tc_webview.setWebViewClient(new com.tencent.smtt.sdk.WebViewClient()
            {
                @Override
                public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
//                    super.onReceivedSslError(webView, sslErrorHandler, sslError);
                    System.out.println("sslErrorHandler....");
                    sslErrorHandler.proceed();
                }

                @Override
                public void onPageFinished(com.tencent.smtt.sdk.WebView webView, String s) {
                    super.onPageFinished(webView, s);
                    System.out.println("onPageFinished....");
                    DialogUIUtils.dismiss(buildBean);
                }

                @Override
                public void onPageStarted(com.tencent.smtt.sdk.WebView webView, String s, Bitmap bitmap) {
                    super.onPageStarted(webView, s, bitmap);
                    System.out.println("onPageStarted....");
                    buildBean.show();
                }
            });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.header_back:
                finish();
                break;
        }
    }
}
